package app.server.project.main.service.controller.cms;

import app.server.project.core.http.CMSBasePage;
import app.server.project.core.http.CMSLstResp;
import app.server.project.core.http.RespModel;
import app.server.project.core.httpauth.UnAuth;
import app.server.project.main.service.db.dao.cfg.ChannelCfgDao;
import app.server.project.main.service.db.entity.cfg.ChannelCfgEntity;
import app.server.project.main.service.db.entity.statics.StaticsActiveEntity;
import app.server.project.main.service.db.entity.user.UserInviteEntity;
import app.server.project.main.service.dto.cms.*;
import app.server.project.main.service.service.InviteService;
import app.server.project.main.service.service.UserInfoService;
import app.server.project.main.service.service.auth.AuthService;
import app.server.project.main.service.service.cms.BusinessService;
import app.server.project.main.service.service.race.RaceService;
import app.server.project.main.service.service.race.UserRaceDetailService;
import app.server.project.main.service.service.withdraw.WithDrawService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@AllArgsConstructor
@RestController
@RequestMapping("/cmsapi/business")
@Slf4j
public class CMSBusinessController {

    private BusinessService businessService;
    private AuthService authService;
    private InviteService inviteService;
    private ChannelCfgDao channelCfgDao;
    private UserRaceDetailService userRaceDetailService;
    private RaceService raceService;
    private UserInfoService userInfoService;
    private WithDrawService withDrawService;


    /**
     * 查询玩家列表
     *
     * @param req
     */
    @PostMapping("/getAllUserInfo")
    public CMSLstResp<CMSUserInfoDto> getAllUserInfo(QueryUserInfoReq req) {
        return this.businessService.getAllUserInfo(req);
    }

    /**
     * 查询玩家列表
     *
     * @param req
     */
    @PostMapping("/getInviteFriend")
    public CMSLstResp<UserInviteEntity> getInviteFriend(QueryUserInfoReq req) {
        return this.inviteService.getInviteFriend(req);
    }

    /**
     * 封号
     *
     * @param req
     */
    @PostMapping("/lockAccount")
    public RespModel lockAccount(@RequestBody LockAccountReq req) {
        this.authService.lockAccount(req);
        return RespModel.success();
    }

    @PostMapping("/setInner")
    public RespModel setInner(@RequestBody LockAccountReq req) {
        this.userInfoService.setInner(req);
        return RespModel.success();
    }

    /**
     * 解绑
     *
     * @param req
     * @return
     */
    @PostMapping("/unBindAccount")
    public RespModel unBindAccount(@RequestBody UnBindAccountReq req) {
        this.authService.unBindAccount(req);
        return RespModel.success();
    }

    /**
     * 查询活跃表
     *
     * @param req
     */
    @PostMapping("/getActiveData")
    public CMSLstResp<StaticsActiveEntity> getActiveData(QueryActiveReq req) {
        return this.businessService.getActiveData(req);
    }

    /**
     * 最近1小时在线人数
     *
     * @param req
     * @return
     */
    @PostMapping("/getOnlineNum")
    public CMSLstResp<OnlineDto> getOnlineNum(CMSBasePage req) {
        return this.businessService.getOnlineNum();
    }

    /**
     * 获取
     *
     * @param req
     * @return
     */
    @UnAuth
    @RequestMapping("/getAdChannel")
    public List<ChannelCfgEntity> getAdChannel() {
        return this.channelCfgDao.list();
    }

    /**
     * 获取
     *
     * @param req
     * @return
     */
    @PostMapping("/saveAdChannel")
    public void saveAdChannel(@RequestBody ChannelCfgEntity req) {
        req.setText(req.getId());
        this.channelCfgDao.saveOrUpdate(req);
    }

    /**
     * 获取
     *
     * @param req
     * @return
     */
    @PostMapping("/deleteAdChannel")
    public void deleteAdChannel(@RequestBody ChannelCfgEntity req) {
        this.channelCfgDao.removeById(req.getId());
    }

    /**
     * 获取
     *
     * @param req
     * @return
     */
    @PostMapping("/getCoins")
    public CMSLstResp getCoins() {
        return this.userRaceDetailService.getCoins();
    }

    /**
     * 获取
     *
     * @param req
     * @return
     */
    @PostMapping("/getCoinLstByUserId")
    public CMSLstResp<CoinDto> getCoinLstByUserId(QueryUserInfoReq req) {
        return this.raceService.getCoinLstByUserId(req.getTargetUserId());
    }


    /**
     * 下载比特币提现单
     *
     * @param req
     * @return
     */
    @PostMapping("/getAllByParam")
    public CMSLstResp getAllByParam(QueryWithDrawReq req) {
        return this.withDrawService.getAllByParam(req);
    }

    /**
     * 下载比特币提现单
     *
     * @param req
     * @return
     */
    @PostMapping("/pass")
    public RespModel pass(@RequestBody List<Long> req) {
        this.withDrawService.pass(req);
        return RespModel.success();
    }

    /**
     * 拒绝
     *
     * @param req
     * @return
     */
    @PostMapping("/reject")
    public RespModel reject(@RequestBody List<Long> req) {
        this.withDrawService.reject(req);
        return RespModel.success();
    }


}
